<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>商城 - 购物车</title>
		<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
		<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
		<link rel="stylesheet" type="text/css" href="../public/index.css"/>
	</head>

	<body>
		<div id="header">
			<div style="height: 40px;" class="container">
				<div class="header-left">
					<a href="../index.php">商城</a>
				</div>
				<div class="header-right">
					<a href="../registered.php">注册</a>
					<a href="../login.php">登录</a>
					<a href="../personal.php">个人中心</a>
					<a href="../cancellation.php">注销</a>
					<a href="index.php">购物车</a>
					<a href="javascript:;">查看订单</a>
				</div>
			</div>
		</div>
		<div id="main">
			<div class="container">
				<div class="car">
					<a href="../index.php">继续购物</a>
					<table style="text-align: center;background-color: #fff;padding: 5px;" border="1">
							<?php
								include "../../public/commom/config.php";
								include "../../public/commom/commom.php";
								
								if(isset($_SESSION["shop"])){
									if(count($_SESSION["shop"])) {
										echo "<thead>
												<tr>
													<th>名称</th>
													<th>图片</th>
													<th>单价</th>
													<th>库存</th>
													<th>数量</th>
													<th>小计</th>
													<th>操作</th>
												</tr>
											</thead>";
										
										$num = 0;
										foreach($_SESSION["shop"] as $shop) {
											echo "<tbody>
													<tr>
														<td>" . $shop["name"] . "</td>
														<td><img src='" . $imgPathThumb . $shop["img"] . "' width='40px'/></td>
														<td>" . $shop["pice"] . "</td>
														<td>" . $shop["inventory"] . "</td>
														<td><a class='car-btn left' href='minus.php?id=" . $shop["id"] . "'><i class='fas fa-minus'></i></a><input type='text' value=" . $shop["num"] . " /><a class='car-btn right' href='add.php?id=" . $shop["id"] . "'><i class='fas fa-plus'></i></a></td>
														<td>" . $shop["pice"] * $shop["num"] . "</td>
														<td><a href='delete.php?id=" . $shop["id"] . "'>删除</a></td>
													</tr>
												</tbody>";
												
											$sheif = $shop["pice"] * $shop["num"];
											$num = $sheif + $num;
										}
										echo "<tr><th colspan='7'>共计</th></tr>
											<tr><td colspan='7'>" . $num . " 元</td></tr>
											<tr><td colspan='7'><a href='delete.php'>清空购物车</a></td></tr>";
									}else {
										
										echo "<h1 style='text-align: center;margin-top: 25%;color: #b0b0b0;font-size: 36px;font-weight: bold;'>您的购物车还是空的！</h1>";
									}
								}else {
									if(isset($_SESSION["user_id"])) {
										echo "<h1 style='text-align: center;margin-top: 25%;color: #b0b0b0;font-size: 36px;font-weight: bold;'>您的购物车还是空的！</h1>";
									}else {
										echo "<h1 style='text-align: center;margin-top: 25%;color: #b0b0b0;font-size: 36px;font-weight: bold;'>您的购物车还是空的！</h1>
										<h2 style='text-align: center;color: #b0b0b0;font-size: 30px;font-weight: bold;'>还未登录请<a href='../login.php'>点击登录</a><h2>";
									}
								}
							?>
					</table>			
				</div>
				<div class="touch">
					<table style="text-align: center;background-color: #fff;padding: 5px;" border="1">
						<?php
							if(isset($_SESSION["user_id"])) {
								if(count($_SESSION["shop"])) {
									echo "<thead>
										<tr>
											<th>操作</th>
											<th>用户名</th>
											<th>姓名</th>
											<th>地址</th>
											<th>电话</th>
											<th>邮箱</th>
										</tr>
									</thead>";
									
									$sql = "SELECT touch.*, user.username FROM touch LEFT JOIN user ON (touch.user_id = user.id) WHERE user_id = " . $_SESSION["user_id"] . "";
									
									$result = mysqli_query($conn, $sql);
									
									while($row = mysqli_fetch_array($result)) {
										echo "<tbody>
												<tr>
													<td><input type='radio' /></td>
													<td>" . $row["username"] . "</td>
													<td>" . $row["name"] . "</td>
													<td>" . $row["addr"] . "</td>
													<td>" . $row["tel"] . "</td>
													<td>" . $row["email"] . "</td>
												</tr>
											</tbody>";
									}
								}
							}
						?>
					</table>
				</div>
			</div>
		</div>
		<div id="footer">
			
		</div>
	</body>

</html>